package com.gopay.common.domain.cert;

import com.gopay.common.cipher.utils.SensitiveInfoUtils;
import com.gopay.common.domain.BaseEntity;

import javax.persistence.*;
import java.util.Date;

/**
 * 商户服务器证书实体类
 * @CorpMsgSignCert.java
 * @author liuyong
 *  @2016年9月15日 下午1:42:48  www.gopay.com.cn Inc.All rights reserved.
 */
@Entity
@Table(name = "CORP_MSG_SIGN_CERT")
public class CorpMsgSignCert extends BaseEntity{


    private static final long serialVersionUID = 1366817668755877082L;

    /**
     * 客户服务器证书主键
     */
    @Id
    @SequenceGenerator(name = "CORP_MSG_SIGN_CERT_SEQ_GENERATOR", sequenceName = "CORP_MSG_SIGN_CERT_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CORP_MSG_SIGN_CERT_SEQ_GENERATOR")
    @Column(name = "ID")
    private Long id;

    @Column(name="CUST_ID", nullable = false, length = 10)
    private String custId;

    @Column(name="SN", nullable = false, length = 100)
    private String sn;

    @Column(name="CERT_ALIAS",  length = 100)
    private String certAlias;

    @Column(name="CERT_EMAIL",  length = 100)
    private String certEmail;

    @Column(name="PASSWORD",  length = 100)
    private String password;

    @Column(name="PUBLIC_KEY", nullable = false, length = 4000)
    private String publicKey;

    @Column(name="PRIVATE_KEY", nullable = false, length = 4000)
    private String privateKey;

    @Column(name="PRIVATE_KEY_PCI", length = 4000) //生产优化12期 lx 将证书内容使用PCI加密方式进行加密 2017-11-23 13:12:26
    private String privateKeyPCI;

    @Column(name="CERT_REQ_BUF", nullable = false, length = 4000)
    private String certReqBuf;

    @Column(name="CERT_SIGN_BUF", nullable = false, length = 4000)
    private String certSignBuf;

    @Column(name="CERT_SIGN_BUF_PCI",  length = 4000) //生产优化12期 lx 将证书内容使用PCI加密方式进行加密 2017-11-23 13:12:26
    private String certSignBufPCI;

    @Column(name="ISSUER", length = 500)
    private String issuer;

    @Column(name="VALID_FROM", nullable = false)
    private Date validForm;

    @Column(name="VALID_TO", nullable = false)
    private Date validTo;

    @Column(name="STAT", nullable = false,length = 1)
    private String stat;

    @Column(name="EXPIRE_NOTIFY_TS")
    private Date expireNotifyTs;

    @Column(name="EXPIRE_NOTIFY_COUNT")
    private String expireNotifyCount;

    @Column(name="CREATE_TS")
    private Date CreateTs;

    @Column(name="LAST_UPT_OPER_ID",length = 12)
    private String lastUptOperId;

    @Column(name="LAST_UPT_TS")
    private Date lastUptTs;

    @Column(name="VERSION")
    private int version;

    @Column(name="CHANGE_REASON", length = 200)
    private String changeResion;

    @Column(name="REMARK", length = 200)
    private String remark;

    @Column(name="PFXCERT", length = 4000)
    private String pfxCert;

    @Column(name="APPLY_CHANGE_TS")
    private Date applyChangeTs;


    /**
     * 生产优化12期 lx 将证书内容使用PCI加密方式进行加密 2017-11-23 13:12:26 ；加密后可能超过varchar2 最大长度 所以数据库以clob存储
     * 由于 出现 以下异常 所以 必须保证 zzpfxCertPCI 为字母顺序的 最后一个  故前方 增加"zz"
     * Oracle ORA-24816 inserting and updating data for entities containg LOB attributes
     */
    @Lob
    @Basic(fetch = FetchType.EAGER)
    @Column(name="PFXCERT_PCI",columnDefinition = "CLOB")
    private String zzpfxCertPCI;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCustId() {
        return custId;
    }

    public void setCustId(String custId) {
        this.custId = custId;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getCertAlias() {
        return certAlias;
    }

    public void setCertAlias(String certAlias) {
        this.certAlias = certAlias;
    }

    public String getCertEmail() {
        return certEmail;
    }

    public void setCertEmail(String certEmail) {
        this.certEmail = certEmail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    public String getCertReqBuf() {
        return certReqBuf;
    }

    public void setCertReqBuf(String certReqBuf) {
        this.certReqBuf = certReqBuf;
    }

    public String getCertSignBuf() {
        return certSignBuf;
    }

    public void setCertSignBuf(String certSignBuf) {
        this.certSignBuf = certSignBuf;
    }

    public String getIssuer() {
        return issuer;
    }

    public void setIssuer(String issuer) {
        this.issuer = issuer;
    }

    public Date getValidForm() {
        return validForm;
    }

    public void setValidForm(Date validForm) {
        this.validForm = validForm;
    }

    public Date getValidTo() {
        return validTo;
    }

    public void setValidTo(Date validTo) {
        this.validTo = validTo;
    }

    public String getStat() {
        return stat;
    }

    public void setStat(String stat) {
        this.stat = stat;
    }

    public Date getExpireNotifyTs() {
        return expireNotifyTs;
    }

    public void setExpireNotifyTs(Date expireNotifyTs) {
        this.expireNotifyTs = expireNotifyTs;
    }

    public String getExpireNotifyCount() {
        return expireNotifyCount;
    }

    public void setExpireNotifyCount(String expireNotifyCount) {
        this.expireNotifyCount = expireNotifyCount;
    }

    public Date getCreateTs() {
        return CreateTs;
    }

    public void setCreateTs(Date createTs) {
        CreateTs = createTs;
    }

    public String getLastUptOperId() {
        return lastUptOperId;
    }

    public void setLastUptOperId(String lastUptOperId) {
        this.lastUptOperId = lastUptOperId;
    }

    public Date getLastUptTs() {
        return lastUptTs;
    }

    public void setLastUptTs(Date lastUptTs) {
        this.lastUptTs = lastUptTs;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public String getChangeResion() {
        return changeResion;
    }

    public void setChangeResion(String changeResion) {
        this.changeResion = changeResion;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getPfxCert() {
        return pfxCert;
    }

    public void setPfxCert(String pfxCert) {
        this.pfxCert = pfxCert;
    }

    public Date getApplyChangeTs() {
        return applyChangeTs;
    }

    public void setApplyChangeTs(Date applyChangeTs) {
        this.applyChangeTs = applyChangeTs;
    }

    public String getPrivateKeyPCI() {
        return SensitiveInfoUtils.smartDecryptWithCheck(privateKeyPCI);
    }

    public void setPrivateKeyPCI(String privateKeyPCI) {
        this.privateKeyPCI = SensitiveInfoUtils.smartEncryptWithCheck(privateKeyPCI);
    }

    public String getCertSignBufPCI() {
        return SensitiveInfoUtils.smartDecryptWithCheck(certSignBufPCI);
    }

    public void setCertSignBufPCI(String certSignBufPCI) {
        this.certSignBufPCI = SensitiveInfoUtils.smartEncryptWithCheck(certSignBufPCI);
    }

    public String getPfxCertPCI() {
        return SensitiveInfoUtils.smartDecryptWithCheck(zzpfxCertPCI);
    }

    public void setPfxCertPCI(String pfxCertPCI) {
        this.zzpfxCertPCI = SensitiveInfoUtils.smartEncryptWithCheck(pfxCertPCI);
    }
}
